﻿using System.IO;
using System.Runtime.Serialization;

namespace HttpPublish
{
    [DataContract]
    public class PublishConfigration
    {
        [DataMemberAttribute]
        public string Host = "";
        [DataMemberAttribute]
        public string Local = "";
        [DataMemberAttribute]
        public string Remote = "";
        [DataMemberAttribute]
        public string User = "";
        [DataMemberAttribute]
        public string Password = "";
        [DataMemberAttribute]
        public string[] Extensions;
        [DataMemberAttribute]
        public string[] Exclude;
        [DataMemberAttribute]
        public int Timeout;

        public static PublishConfigration LoadConfig(string filePath)
        {
            var data = File.ReadAllText(filePath);
            var config = JsonHelper.Deserialize<PublishConfigration>(data);
            if (config.Extensions == null)
                config.Extensions = new[] {".js", ".html", ".htm", ".gif", ".jpg", ".png", ".php"};
            if (config.Timeout == 0)
                config.Timeout = 60000;
            return config;
        }
    }
}
